<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2018/5/29
 * Time: 13:51
 */
namespace App\Http\Controllers\Api;
use Illuminate\Routing\Controller;
use EasyWeChat\Factory;
class WeChatControllerBase extends Controller{
    protected $app;
    public function __construct()
    {

        $this->app=self::initInstance();
    }

    public static function initInstance() {
        $config = [
            'app_id' => env('WECHAT_APPID'),
            'secret' => env('WECHAT_APP_SECRET'),

            // 下面为可选项
            // 指定 API 调用返回结果的类型：array(default)/collection/object/raw/自定义类名
            'response_type' => 'array',

            'log' => [
                'level' => 'debug',
                'file' => storage_path().'/logs/wechat.log',
            ],
        ];

        $app = Factory::miniProgram($config);
        return $app;
    }

    public function getAppInstance() {
        return $this->app;
    }
}